# _*_ coding : utf-8 _*_
import urllib.request
import ssl
import json
import time

# 关闭证书认证
ssl._create_default_https_context = ssl._create_unverified_context


def getlist():
    # 得到数据信息
    data0 = urllib.request.urlopen(
        "https://kyfw.12306.cn/otn/leftTicket/query?leftTicketDTO.train_date=2017-02-26&leftTicketDTO.from_station=CSQ&leftTicketDTO.to_station=CDW&purpose_codes=ADULT", ).read()
    # 转变数据信息 json -> dictionary
    data1 = json.loads(data0)
    return data1['data2']


list_s = getlist()[1]
print(list_s['queryLeftNewDTO']['yw_num'])
while list_s['queryLeftNewDTO']['yw_num'] == '无'or list_s['queryLeftNewDTO']['yw_num'] == '--':
    print(list_s['queryLeftNewDTO']['yw_num'])
    time.sleep(5)
    continue
